package conlon.seata02.controller;


import conlon.api.Seata02Api;
import conlon.api.form.AccountForm;
import conlon.api.form.StoreForm;
import conlon.seata02.entity.AccountEntity;
import conlon.seata02.entity.StoreEntity;
import conlon.seata02.service.AccountService;
import conlon.seata02.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author conlon
 * @since 2021-08-16
 */
@RestController
@RequestMapping("/Seata02Api")
public class ApiController implements Seata02Api {


    @Autowired
    public AccountService accountService;

    @Autowired
    private StoreService storeService;


    @Override
    @ResponseBody
    @PostMapping(value = "/createAccount")
    public void createAccount(@RequestBody AccountForm form) {
        accountService.createAccount(form);
        System.out.println(form);
    }

    @Override
    @ResponseBody
    @PostMapping(value = "/createStore")
    public void createStore(@RequestBody StoreForm form) {
        try {
            Thread.sleep(300000);
            storeService.createStore(form);
            System.out.println(form);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}